﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace Maticsoft.DAL
{
	/// <summary>
	/// 数据访问类:supplier_bidplan
	/// </summary>
	public partial class supplier_bidplan
	{
		public supplier_bidplan()
		{}
        #region  BasicMethod

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return DbHelperSQL.GetMaxID("supplier_bidplan_id", "supplier_bidplan");
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int supplier_bidplan_id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from supplier_bidplan");
            strSql.Append(" where supplier_bidplan_id=@supplier_bidplan_id");
            SqlParameter[] parameters = {
					new SqlParameter("@supplier_bidplan_id", SqlDbType.Int,4)
			};
            parameters[0].Value = supplier_bidplan_id;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Maticsoft.Model.supplier_bidplan model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into supplier_bidplan(");
            strSql.Append("supplier_id,dpid,submit_user_id,subTime,isBidFee,isBidDeposit,bidFeeTime,bidDepositTime,confirmBidFee_user_id,confirmBidDeposit_user_id,isSendBidPlan)");
            strSql.Append(" values (");
            strSql.Append("@supplier_id,@dpid,@submit_user_id,@subTime,@isBidFee,@isBidDeposit,@bidFeeTime,@bidDepositTime,@confirmBidFee_user_id,@confirmBidDeposit_user_id,@isSendBidPlan)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@supplier_id", SqlDbType.Int,4),
					new SqlParameter("@dpid", SqlDbType.Int,4),
					new SqlParameter("@submit_user_id", SqlDbType.Int,4),
					new SqlParameter("@subTime", SqlDbType.DateTime),
					new SqlParameter("@isBidFee", SqlDbType.Bit,1),
					new SqlParameter("@isBidDeposit", SqlDbType.Bit,1),
					new SqlParameter("@bidFeeTime", SqlDbType.DateTime),
					new SqlParameter("@bidDepositTime", SqlDbType.DateTime),
					new SqlParameter("@confirmBidFee_user_id", SqlDbType.Int,4),
					new SqlParameter("@confirmBidDeposit_user_id", SqlDbType.Int,4),
					new SqlParameter("@isSendBidPlan", SqlDbType.Bit,1)};
            parameters[0].Value = model.supplier_id;
            parameters[1].Value = model.dpid;
            parameters[2].Value = model.submit_user_id;
            parameters[3].Value = model.subTime;
            parameters[4].Value = model.isBidFee;
            parameters[5].Value = model.isBidDeposit;
            parameters[6].Value = model.bidFeeTime;
            parameters[7].Value = model.bidDepositTime;
            parameters[8].Value = model.confirmBidFee_user_id;
            parameters[9].Value = model.confirmBidDeposit_user_id;
            parameters[10].Value = model.isSendBidPlan;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Maticsoft.Model.supplier_bidplan model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update supplier_bidplan set ");
            strSql.Append("supplier_id=@supplier_id,");
            strSql.Append("dpid=@dpid,");
            strSql.Append("submit_user_id=@submit_user_id,");
            strSql.Append("subTime=@subTime,");
            strSql.Append("isBidFee=@isBidFee,");
            strSql.Append("isBidDeposit=@isBidDeposit,");
            strSql.Append("bidFeeTime=@bidFeeTime,");
            strSql.Append("bidDepositTime=@bidDepositTime,");
            strSql.Append("confirmBidFee_user_id=@confirmBidFee_user_id,");
            strSql.Append("confirmBidDeposit_user_id=@confirmBidDeposit_user_id,");
            strSql.Append("isSendBidPlan=@isSendBidPlan");
            strSql.Append(" where supplier_bidplan_id=@supplier_bidplan_id");
            SqlParameter[] parameters = {
					new SqlParameter("@supplier_id", SqlDbType.Int,4),
					new SqlParameter("@dpid", SqlDbType.Int,4),
					new SqlParameter("@submit_user_id", SqlDbType.Int,4),
					new SqlParameter("@subTime", SqlDbType.DateTime),
					new SqlParameter("@isBidFee", SqlDbType.Bit,1),
					new SqlParameter("@isBidDeposit", SqlDbType.Bit,1),
					new SqlParameter("@bidFeeTime", SqlDbType.DateTime),
					new SqlParameter("@bidDepositTime", SqlDbType.DateTime),
					new SqlParameter("@confirmBidFee_user_id", SqlDbType.Int,4),
					new SqlParameter("@confirmBidDeposit_user_id", SqlDbType.Int,4),
					new SqlParameter("@isSendBidPlan", SqlDbType.Bit,1),
					new SqlParameter("@supplier_bidplan_id", SqlDbType.Int,4)};
            parameters[0].Value = model.supplier_id;
            parameters[1].Value = model.dpid;
            parameters[2].Value = model.submit_user_id;
            parameters[3].Value = model.subTime;
            parameters[4].Value = model.isBidFee;
            parameters[5].Value = model.isBidDeposit;
            parameters[6].Value = model.bidFeeTime;
            parameters[7].Value = model.bidDepositTime;
            parameters[8].Value = model.confirmBidFee_user_id;
            parameters[9].Value = model.confirmBidDeposit_user_id;
            parameters[10].Value = model.isSendBidPlan;
            parameters[11].Value = model.supplier_bidplan_id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int supplier_bidplan_id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from supplier_bidplan ");
            strSql.Append(" where supplier_bidplan_id=@supplier_bidplan_id");
            SqlParameter[] parameters = {
					new SqlParameter("@supplier_bidplan_id", SqlDbType.Int,4)
			};
            parameters[0].Value = supplier_bidplan_id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string supplier_bidplan_idlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from supplier_bidplan ");
            strSql.Append(" where supplier_bidplan_id in (" + supplier_bidplan_idlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.Model.supplier_bidplan GetModel(int supplier_bidplan_id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 supplier_bidplan_id,supplier_id,dpid,submit_user_id,subTime,isBidFee,isBidDeposit,bidFeeTime,bidDepositTime,confirmBidFee_user_id,confirmBidDeposit_user_id,isSendBidPlan from supplier_bidplan ");
            strSql.Append(" where supplier_bidplan_id=@supplier_bidplan_id");
            SqlParameter[] parameters = {
					new SqlParameter("@supplier_bidplan_id", SqlDbType.Int,4)
			};
            parameters[0].Value = supplier_bidplan_id;

            Maticsoft.Model.supplier_bidplan model = new Maticsoft.Model.supplier_bidplan();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.Model.supplier_bidplan DataRowToModel(DataRow row)
        {
            Maticsoft.Model.supplier_bidplan model = new Maticsoft.Model.supplier_bidplan();
            if (row != null)
            {
                if (row["supplier_bidplan_id"] != null && row["supplier_bidplan_id"].ToString() != "")
                {
                    model.supplier_bidplan_id = int.Parse(row["supplier_bidplan_id"].ToString());
                }
                if (row["supplier_id"] != null && row["supplier_id"].ToString() != "")
                {
                    model.supplier_id = int.Parse(row["supplier_id"].ToString());
                }
                if (row["dpid"] != null && row["dpid"].ToString() != "")
                {
                    model.dpid = int.Parse(row["dpid"].ToString());
                }
                if (row["submit_user_id"] != null && row["submit_user_id"].ToString() != "")
                {
                    model.submit_user_id = int.Parse(row["submit_user_id"].ToString());
                }
                if (row["subTime"] != null && row["subTime"].ToString() != "")
                {
                    model.subTime = DateTime.Parse(row["subTime"].ToString());
                }
                if (row["isBidFee"] != null && row["isBidFee"].ToString() != "")
                {
                    if ((row["isBidFee"].ToString() == "1") || (row["isBidFee"].ToString().ToLower() == "true"))
                    {
                        model.isBidFee = true;
                    }
                    else
                    {
                        model.isBidFee = false;
                    }
                }
                if (row["isBidDeposit"] != null && row["isBidDeposit"].ToString() != "")
                {
                    if ((row["isBidDeposit"].ToString() == "1") || (row["isBidDeposit"].ToString().ToLower() == "true"))
                    {
                        model.isBidDeposit = true;
                    }
                    else
                    {
                        model.isBidDeposit = false;
                    }
                }
                if (row["bidFeeTime"] != null && row["bidFeeTime"].ToString() != "")
                {
                    model.bidFeeTime = DateTime.Parse(row["bidFeeTime"].ToString());
                }
                if (row["bidDepositTime"] != null && row["bidDepositTime"].ToString() != "")
                {
                    model.bidDepositTime = DateTime.Parse(row["bidDepositTime"].ToString());
                }
                if (row["confirmBidFee_user_id"] != null && row["confirmBidFee_user_id"].ToString() != "")
                {
                    model.confirmBidFee_user_id = int.Parse(row["confirmBidFee_user_id"].ToString());
                }
                if (row["confirmBidDeposit_user_id"] != null && row["confirmBidDeposit_user_id"].ToString() != "")
                {
                    model.confirmBidDeposit_user_id = int.Parse(row["confirmBidDeposit_user_id"].ToString());
                }
                if (row["isSendBidPlan"] != null && row["isSendBidPlan"].ToString() != "")
                {
                    if ((row["isSendBidPlan"].ToString() == "1") || (row["isSendBidPlan"].ToString().ToLower() == "true"))
                    {
                        model.isSendBidPlan = true;
                    }
                    else
                    {
                        model.isSendBidPlan = false;
                    }
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select supplier_bidplan_id,supplier_id,dpid,submit_user_id,subTime,isBidFee,isBidDeposit,bidFeeTime,bidDepositTime,confirmBidFee_user_id,confirmBidDeposit_user_id,isSendBidPlan ");
            strSql.Append(" FROM supplier_bidplan ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" supplier_bidplan_id,supplier_id,dpid,submit_user_id,subTime,isBidFee,isBidDeposit,bidFeeTime,bidDepositTime,confirmBidFee_user_id,confirmBidDeposit_user_id,isSendBidPlan ");
            strSql.Append(" FROM supplier_bidplan ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM supplier_bidplan ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.supplier_bidplan_id desc");
            }
            strSql.Append(")AS Row, T.*  from supplier_bidplan T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "supplier_bidplan";
            parameters[1].Value = "supplier_bidplan_id";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
		#region  ExtensionMethod
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetListByView(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM Vsupplier_bidplan ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
		#endregion  ExtensionMethod
	}
}

